package com.ruoyi.web.controller.ltd_web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.ltd_web.domain.LtdContent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ltd_web.domain.LtdNews;
import com.ruoyi.ltd_web.service.ILtdNewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 公司动态信息Controller
 *
 * @author ruoyi
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/system/news")
public class LtdNewsController extends BaseController
{
    @Autowired
    private ILtdNewsService ltdNewsService;

    /**
     * 查询公司动态信息列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(LtdNews ltdNews)
    {
        startPage();
        List<LtdNews> list = ltdNewsService.selectLtdNewsList(ltdNews);
        return getDataTable(list);
    }

    /**
     * 导出公司动态信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "公司动态信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LtdNews ltdNews)
    {
        List<LtdNews> list = ltdNewsService.selectLtdNewsList(ltdNews);
        ExcelUtil<LtdNews> util = new ExcelUtil<LtdNews>(LtdNews.class);
        util.exportExcel(response, list, "公司动态信息数据");
    }

    /**
     * 获取公司动态信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ltdNewsService.selectLtdNewsById(id));
    }

    /**
     * 新增公司动态信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:add')")
    @Log(title = "公司动态信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LtdNews ltdNews)
    {
        return toAjax(ltdNewsService.insertLtdNews(ltdNews));
    }

    /**
     * 修改公司动态信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "公司动态信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LtdNews ltdNews)
    {
        return toAjax(ltdNewsService.updateLtdNews(ltdNews));
    }

    /**
     * 删除公司动态信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:remove')")
    @Log(title = "公司动态信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ltdNewsService.deleteLtdNewsByIds(ids));
    }

    /**
     * 上传图片
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "动态--上传图片", businessType = BusinessType.UPDATE)
    @PostMapping("/upload_pic/")
    public AjaxResult upload_pic(@RequestParam("file") MultipartFile file){

        return ltdNewsService.news_upload_pic(file);
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "公司动态--状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody LtdNews ltdNews)
    {
        return toAjax(ltdNewsService.updateLtdNews(ltdNews));
    }
}
